package org.geekbang.projects.service.impl;

import org.geekbang.projects.service.CacheService;
import org.geekbang.projects.vo.User;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
*   
* @author : KangNing Hu
*/
@Service
@CacheConfig(cacheManager = "redisCacheManager" , cacheNames = "string")
public class CacheServiceImpl implements CacheService {



	@Override
	@Cacheable(key = "'test:' + #key" , sync = true)
	public String get(String key) {
		return "hello word";
	}



	@CacheEvict(key = "'test:' + #key")
	@Override
	public void clean(String key) {

	}


	@Cacheable(key = "'user:' + #key")
	@CachePut(key = "'user:' + #key")
	public User getUser(String key){
		User user = new User();
		user.setId(key);
		user.setName("小王");
		return user;
	}

	@Override
	@CacheEvict(allEntries = true)
	public void cleanAll(String key) {

	}
}
